<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');
require_once BASE_PATH.'app/controller.php';
class Rss extends Controller
{
	private $bbs;
	function __construct()
	{
		parent::__construct();
		$this->_init();
	}
	
	protected function _init() 
	{	
		$this->bbs = Wdk::get('Bbs');
	}
	
	private function _loadBbs($bbs_id='') 
	{	
		if($this->bbs['bbs_id'] === $bbs_id)	return;
		if(trim($bbs_id) === '') throw new NoRecordException("");
		$this->bbs->loadById($bbs_id);
		$this->bbs->setUserSession($this->session);
	}
	
	public function index($bbs_id='')
	{
		/*****************************************************************************************************************************
		* BASIC VARS
		*****************************************************************************************************************************/
		$assign_data = array();
		/****************************************************************************************************************************/
		try
		{
			$this->_loadBbs($bbs_id);
			$assign_data['bbs'] = $this->bbs;
			$lm = Wdk::get('PostManager');
			$lm['listsize'] = 100;
			$lm['page'] = 1;
			$lm['where'] = array("`p`.`fk_bbs_seq` = {$this->bbs['bbs_seq']}");
			$lm->load();
			$assign_data['lists'] = $lm['lists'];
		}
		catch(WException $e){}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/
		parent::_layout('rss');
		echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
		echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
		echo '<channel>'."\n";
		parent::_view($assign_data);
		echo "\n".'</channel>';
		echo "\n".'</rss>';
		/****************************************************************************************************************************/
	}
}
